<?php
class companys extends CI_Controller{
	public function index()
	{
		//Get all companys - /companys  [GET]
	}
	
	public function company($p1 = "", $p2 = "")
	{
		$postData = $this->decoder->Decode();
		
		if ($p1 == "" && $p2 == "" && $_SERVER['REQUEST_METHOD'] == "POST")
		{
			//Add company - /companys/company  [POST]
			$company = $postData->company;
			
			$this->load->model('user_m');
			$this->user_m->username = $company->user->username;
			$this->user_m->email = $company->user->email;
			$this->user_m->password = $company->user->password;
			$this->user_m->phone = $company->user->phone;
			
			
			$this->load->model('company_m');
			$this->company_m->name = $company->name;
			$this->company_m->address = $company->address;
			$this->company_m->user = $this->user_m;
			
			
			$this->load->library('company');
			
			$this->company->Insert($this->company_m);
		}
		
		if ($p1 != "")
		{
			if ($p2 == "")
			{
				if ($_SERVER['REQUEST_METHOD'] == "GET")
				{
					//Get company by mail - /companys/company/$mail  [GET]
					
					$this->load->library('company');
					$company = $this->company->GetByEmail($p1);
					
					echo $this->decoder->Code($company);
					//var_dump($company);
				}
			}
			else
			{
				if ( $p2 == "delete" && $_SERVER['REQUEST_METHOD'] == "GET")
				{
					//Delete company by mail - /companys/company/$mail/delete  [GET]
					$this->load->library('user');
					$this->user->DeleteByEmail($p1);
				}
				
				if ( $p2 == "update" && $_SERVER['REQUEST_METHOD'] == "POST")
				{
					//Update company - /companys/company/$mail/update  [POST]
					
				}
			}
		}
	}
}
?>